package com.ruoyi.client.runjianhr.service.Impl;

import com.alibaba.fastjson.JSON;
import com.github.kevinsawicki.http.HttpRequest;
import com.ruoyi.client.runjianhr.bean.HREmployee;
import com.ruoyi.client.runjianhr.constants.RunjianHRAPIUtils;
import com.ruoyi.client.runjianhr.service.HREmployeeService;
import com.ruoyi.client.runjianhr.service.UtilService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 人员管理
 */
@Service
public class HREmployeeServiceImpl implements HREmployeeService {

    @Resource
    UtilService utilService;
    /**
     * 获取员工列表
     * @return 返回成员列表
     */
    @Override
    public List<HREmployee.data> getEmployeeList() throws Exception{
        List<HREmployee.data> employeeData = new ArrayList<>();
        Map<String,String> map = new HashMap<>();
        //获取token
        String token = utilService.getToken(map);
        //获取人员信息
        String result = HttpRequest.get(RunjianHRAPIUtils.HREmployeeListUrl)
                    .header("Authorization","Bearer "+token)
                    .body();
        //返回数据到实体类
        HREmployee employee = JSON.parseObject(result,HREmployee.class);
        if(employee.getCode()==0 && employee.isSuccessful()){
            employeeData = employee.getData();
        }
        return employeeData;
    }

}
